package com.xingdata.jjxc.utils;

import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

/**
 * 获取视频缩略图
 * 
 * @author Administrator
 * 
 */
public class BitmapThumbnailTask implements Task {
	private final String TAG = "BitmapTask";
	private String url;
	// private LruCache<String, Bitmap> bitMap;
	private Handler handler;
	private boolean isCancel = true;
	private Float fMulriple;

	public BitmapThumbnailTask(String url, Handler handler,Float fMulriple) {
		this.url = url;
		this.handler = handler;
		this.fMulriple=fMulriple;
	}

	@Override
	public void runTask() {
		Log.i(TAG, "正在获取缩略图" + url);
		String imageURL = url.replaceAll(".mp4", ".jpg");
		Bitmap bitmap = SDCardTools.getSDImage(
				ImageTools.changeImageName(imageURL), fMulriple);
		if (bitmap == null) {
			if (url.startsWith("http")) {
				bitmap = VideoTools.createNetVideoThumbnail(url);
			} else {
				bitmap = VideoTools.createVideoThumbnail(url);
			}

			// SDCardTools.SaveUrlImage(imageURL, bitmap);
		}
		BitmapCache.put(url, bitmap);
		Message message = new Message();
		message.what = MessageCode.MessageCode_RefreshControl;
		handler.sendMessage(message);

	}

	@Override
	public void cacelTask() {
		isCancel = false;
	}

	@Override
	public boolean isCancel() {
		return isCancel;
	}

}
